home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / communic / pcmail / aux_ / srctoman.sh < prev   
Encoding:
Text File  |  1994-06-05  |  4.7 KB  |  202 lines

  1. : srctoman - see comment below
  2.  
  3.  
  4.  
  5. : process arguments
  6.  
  7.  
  8.  
  9. while :
  10.  
  11. do
  12.  
  13.     case $1 in
  14.  
  15.  [0-9]) SECT=$1;;
  16.  
  17.      -) LANG=$1; B='[#:]';;
  18.  
  19.   -awk) LANG=$1; B='#';;
  20.  
  21.     -c) LANG=$1; B='\/\*';;
  22.  
  23.     -f) LANG=$1; B='[Cc]';;
  24.  
  25.    -mk) LANG=$1; B='#';;
  26.  
  27.  -n|-t) LANG=$1; B='\\"';;
  28.  
  29.     -p) LANG=$1; B='{';;
  30.  
  31.     -r) LANG=$1; B='#';;
  32.  
  33.     -C) LANG=$1; B=$2; shift;;
  34.  
  35.     -*) ERROR="unknown option: $1"; break;;
  36.  
  37.     "") ERROR="missing file argument"; break;;
  38.  
  39.      *) break;;
  40.  
  41.     esac
  42.  
  43.     shift
  44.  
  45. done
  46.  
  47.  
  48.  
  49. : check error status
  50.  
  51.  
  52.  
  53. case $ERROR in
  54.  
  55. "") ;;
  56.  
  57.  *) echo "$0: $ERROR" 1>&2
  58.  
  59.     echo "usage: $0 [-|-awk|-c|-f|-mk|-n|-p|-t|-r] [section] file(s)" 1>&2; exit 1;;
  60.  
  61. esac
  62.  
  63.  
  64.  
  65. : set up for file suffix processing
  66.  
  67.  
  68.  
  69. case $LANG in
  70.  
  71. "") sh='[:#]';    r='#';    rh=$r;    awk='#'; mk='#';
  72.  
  73.     c='\/\*';    h=$c;    y=$c;    l=$c;
  74.  
  75.     f='[Cc]';    fh=$f;    p='{';    ph=$p;
  76.  
  77.     ms='\\"';    nr=$ms;    mn=$ms;    man=$ms;
  78.  
  79. esac
  80.  
  81.  
  82.  
  83. : extract comments
  84.  
  85.  
  86.  
  87. for i in $*
  88.  
  89. do
  90.  
  91.     case $LANG in
  92.  
  93.     "") eval B\="\$`expr $i : '^.*\.\([^.]*\)$'`"
  94.  
  95.     test "$B" || { echo "$0: unknown suffix: $i; assuming c" 1>&2; B=$c; }
  96.  
  97.     esac
  98.  
  99.     sed '
  100.  
  101.     /^'"$B"'++/,/^'"$B"'--/!d
  102.  
  103.     /^'"$B"'++/d
  104.  
  105.     /^'"$B"'--/d
  106.  
  107.     s/[     ]*$//
  108.  
  109.     /^'"$B"' \([A-Z]\)/{
  110.  
  111.     s//\1/
  112.  
  113.     /^NAME/{
  114.  
  115.         N
  116.  
  117.         s/^.*\n'"$B"'[     ]*//
  118.  
  119.         h
  120.  
  121.         y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
  122.  
  123.         s/^.*$/.TH & '"$SECT"'\
  124.  
  125. .ad\
  126.  
  127. .fi\
  128.  
  129. .SH NAME/
  130.  
  131.         p
  132.  
  133.         g
  134.  
  135.         s/ [0-9]$//
  136.  
  137.         a\
  138.  
  139. \\-
  140.  
  141.         p
  142.  
  143.         d
  144.  
  145.     }
  146.  
  147.     /^SUMMARY/d
  148.  
  149.     /^DESCRIPTION/s//.SH &\
  150.  
  151. .ad\
  152.  
  153. .fi/
  154.  
  155.     /^BUGS/s//.SH &\
  156.  
  157. .ad\
  158.  
  159. .fi/
  160.  
  161.     /^DIAGNOSTICS/s//.SH &\
  162.  
  163. .ad\
  164.  
  165. .fi/
  166.  
  167.     /^[A-Z][A-Z][A-Z][^a-z]*$/s//.SH &\
  168.  
  169. .na\
  170.  
  171. .nf/
  172.  
  173.     p
  174.  
  175.     d
  176.  
  177.     }
  178.  
  179.     s/^'"$B"'[     ]*//
  180.  
  181.     s/^[     ]*$//
  182.  
  183. ' $i
  184.  
  185. done 
  186.  
  187.  
  188.  
  189. exit
  190.  
  191.  
  192.  
  193. :++
  194.  
  195. : NAME
  196.  
  197. :    srctoman 1
  198.  
  199. : SUMMARY
  200.  
  201. :    extract manual page from source file comment
  202.  
  203. : PACKAGE
  204.  
  205. :    source file maintentance tools
  206.  
  207. : SYNOPSIS
  208.  
  209. :    srctoman [-|-awk|-c|-f|-mk|-m|-n|-p|-t|-r] [section] file(s)
  210.  
  211. : DESCRIPTION
  212.  
  213. :    Srctoman converts comments in various programming languages to
  214.  
  215. :    UNIX-style manual pages.
  216.  
  217. :    The command processes comments in the style of newsource(1);
  218.  
  219. :    its standard output is suitable for formatting with nroff(1) or 
  220.  
  221. :    troff(1) using the "-man" macro package.  
  222.  
  223. :    Typically, srctoman is integrated with make(1) scripts.
  224.  
  225. :
  226.  
  227. :    Source files are processed in the indicated order; if no
  228.  
  229. :    files argument the command produces no output.
  230.  
  231. :
  232.  
  233. :    The source file language can be specified through a command-line
  234.  
  235. :    option, or can be implied by the filename suffix.
  236.  
  237. :    The expected start-of-comment symbol is shown in the last column.
  238.  
  239. :
  240.  
  241. : .nf
  242.  
  243.     option    language    comment
  244.  
  245.  
  246.  
  247.     -    shell        [:#]
  248.  
  249.     -awk    awk        #
  250.  
  251.     -c    c        /*
  252.  
  253.     -f    fortran        [Cc]
  254.  
  255.     -mk    make        #
  256.  
  257.     -n    nroff        \\"
  258.  
  259.     -p    pascal        {
  260.  
  261.     -t    troff        \\"
  262.  
  263.     -r    ratfor        #
  264.  
  265.     -C    any language    next argument
  266.  
  267. : .fi
  268.  
  269. :
  270.  
  271. : .nf
  272.  
  273.     suffix    language    comment
  274.  
  275.  
  276.  
  277.     .awk    awk        #
  278.  
  279.     .c    c        /*
  280.  
  281.     .f    fortran        [Cc]
  282.  
  283.     .fh    fortran        [Cc]
  284.  
  285.     .h    c        /*
  286.  
  287.     .l    lex        /*
  288.  
  289.     .man    nroff,troff    \\"
  290.  
  291.     .mk    make        #
  292.  
  293.     .me    nroff,troff    \\"
  294.  
  295.     .ms    nroff,troff    \\"
  296.  
  297.     .nr    nroff,troff    \\"
  298.  
  299.     .p    pascal        {
  300.  
  301.     .ph    pascal        {
  302.  
  303.     .r    ratfor        #
  304.  
  305.     .rh    ratfor        #
  306.  
  307.     .sh    shell        [:#]
  308.  
  309.     .y    yacc        /*
  310.  
  311. : .fi
  312.  
  313. :
  314.  
  315. :    The required format of comments is discussed below, where SOC
  316.  
  317. :    stands for the start-of-comment symbol of the language being used.
  318.  
  319. :
  320.  
  321. :    1) Start of manual: SOC, followed by `++'.
  322.  
  323. :
  324.  
  325. :    2) Section heading: SOC, blank, section name in upper case.
  326.  
  327. :
  328.  
  329. :    3) New paragraph: empty line or line with SOC only.
  330.  
  331. :
  332.  
  333. :    4) All other text: SOC and subsequent blanks or tabs are removed.
  334.  
  335. :    Lines that do not start with SOC are left unchanged (useful for 
  336.  
  337. :    inclusion of program text).
  338.  
  339. :
  340.  
  341. :    5) End of manual: SOC, followed by `--'.
  342.  
  343. :    An end-of-comment may follow if the source file language requires this.
  344.  
  345. :
  346.  
  347. :    The following manual sections receive a special treatment:
  348.  
  349. :    NAME and SUMMARY should appear at the beginning and in
  350.  
  351. :    this order; DESCRIPTION, DIAGNOSTICS and BUGS will be
  352.  
  353. :    right-margin adjusted.
  354.  
  355. :    Other sections may be added freely without confusing srctoman.
  356.  
  357. : COMMANDS
  358.  
  359. :    sh(1), sed(1), expr(1)
  360.  
  361. : SEE ALSO
  362.  
  363. :    newsource(1), modsource(1), xman(1)
  364.  
  365. :    The earlier commands new(1), mod(1), mkman(1) and dssman(1)
  366.  
  367. :    by Ruud Zwart and Ben Noordzij (Erasmus University, Rotterdam) 
  368.  
  369. : DIAGNOSTICS
  370.  
  371. :    The program complains if an unknown language is specified
  372.  
  373. :    or if the language cannot be deduced from the file suffix.
  374.  
  375. : AUTHOR(S)
  376.  
  377. :    W.Z. Venema
  378.  
  379. :    Eindhoven University of Technology
  380.  
  381. :    Department of Mathematics and Computer Science
  382.  
  383. :    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  384.  
  385. : CREATION DATE
  386.  
  387. :    Fri Jan 17 22:59:27 MET 1986
  388.  
  389. : LAST MODIFICATION
  390.  
  391. :    Thu Mar 10 20:08:15 MET 1988
  392.  
  393. : VERSION/RELEASE
  394.  
  395. :    1.20
  396.  
  397. :--
  398.  
  399.  
  400.  
  401.  
  402.  
  403.